package main

type ListNode struct {
	Val  int
	Next *ListNode
}

// 双指针法
func removeNthFromEnd(head *ListNode, n int) *ListNode {
	newhead := &ListNode{0, head}
	first := newhead
	second := head
	for i := 0; i < n; i++ {
		second = second.Next
	}
	for ; second != nil; second = second.Next {
		first = first.Next
	}
	first.Next = first.Next.Next
	return newhead.Next
}
